* Replication Code
* Paper: Effectiveness of Social Norm-Based Nudge Interventions on Food Waste Reduction
* Author: ZHANG Yuchi, UWASU Michinori
*
* This script reproduces the main analyses reported in the paper.
*******************************************************

clear all
set more off

*******************************************************
* 1. Load dataset
*******************************************************

* The dataset must be located in the same folder as this do-file
import delimited "original_data.csv", clear

*******************************************************
* 2. Variable construction
*******************************************************

* Interaction term for Difference-in-Differences
gen interac = week * interv
label var interac "Treatment × Week interaction"

gen full_date = date(date,"YMD")
format full_date %td

* Generate weekday variable
gen weekday = dow(full_date)

* Generate week indicator for the experiment
local start = td(14oct2024)
gen week_4 = floor((full_date - `start')/7) + 1
replace week_4 = week_4 + 1
label var week_4 "Week of experiment (1–4)"

*******************************************************
* 3. Descriptive statistics
*******************************************************

summarize totalweight averageweight numplate coltime

* Descriptive statistics by treatment group
by interv, sort: summarize totalweight averageweight numplate coltime

*******************************************************
* 4. Graph: Trends in food waste
*******************************************************

display date("14oct2024" , "DMY")

twoway (line averageweight full_date if interv == 0, color(blue)) ///
       (line averageweight full_date if interv == 1, color(red)) ///
       , xline(23663, lcolor(black) lwidth(thick)) ///
       legend(order(1 "Control" 2 "Treatment")) ///
       xlabel(, angle(45)) ylabel(, angle(0)) ///
       xtitle("Dates") ytitle("Average weight(g)")
	   
	   
twoway (scatter averageweight full_date if interv == 0, color(blue)) ///
       (scatter averageweight full_date if interv == 1, color(red)) ///
       , xline(23663, lcolor(black) lwidth(thick)) ///
       legend(order(1 "Control" 2 "Treatment")) ///
       xlabel(, angle(45)) ylabel(, angle(0)) ///
       xtitle("Dates") ytitle("Average weight(g)")

*******************************************************
* 5. Drop missing observations
*******************************************************

* Three observations were not collected during the experiment
drop if _n == 5 | _n == 20 | _n == 35

*******************************************************
* 6. Main Difference-in-Differences regressions
*******************************************************

* Model 1: baseline specification
reg averageweight coltime week interv weekday interac, robust
est store reg1

* Model 2: including week fixed effects
reg averageweight coltime week interv weekday week_4 interac, robust
est store reg2

******************************************************************************
* 7. Permutation robustness test for the main DiD regression model 1 in step 6
******************************************************************************

permute interac _b[interac], reps(1000): reg averageweight week interv coltime weekday interac

*******************************************************
* 8. Event-study of weekly DiD treatment effects
*******************************************************

reg averageweight ib1.week_4##i.interv coltime i.weekday, robust
est store event_week

* Weekly DiD treatment effects relative to Week 1
tempname memhold
postfile `memhold' str10 Week coef se pvalue lb ub using did_weekly, replace

lincom 1.interv#2.week_4
post `memhold' ("Week 2") (r(estimate)) (r(se)) (r(p)) (r(lb)) (r(ub))

lincom 1.interv#3.week_4
post `memhold' ("Week 3") (r(estimate)) (r(se)) (r(p)) (r(lb)) (r(ub))

lincom 1.interv#4.week_4
post `memhold' ("Week 4") (r(estimate)) (r(se)) (r(p)) (r(lb)) (r(ub))

postclose `memhold'
use did_weekly, clear

gen event_time = _n + 1

set obs 4
replace event_time = 1 in 4
replace coef = 0 in 4
replace lb = 0 in 4
replace ub = 0 in 4
replace se = . in 4
replace pvalue = . in 4
replace Week = "Week 1" in 4

sort event_time

twoway ///
    (rcap lb ub event_time, lcolor(black) lwidth(medthin)) ///
    (scatter coef event_time, mcolor(black) msymbol(O) msize(medium)), ///
    yline(0, lpattern(dash) lcolor(gs8)) ///
    xlabel(1 "Week 1" 2 "Week 2" 3 "Week 3" 4 "Week 4") ///
    xtitle("Weeks Since Intervention", size(medlarge)) ///
    ytitle("Difference-in-Differences Estimate (grams)", size(medlarge)) ///
    title("Dynamic Treatment Effects of Nudge Intervention", size(large)) ///
    legend(off) ///
    graphregion(color(white)) ///
    plotregion(color(white))

*******************************************************
* End of replication script
*******************************************************